home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / FlashBeepƒ / FlashBeep.c < prev    next >
Text File  |  1993-06-18  |  2KB  |  121 lines

  1. /*
  2.  *    FlashBeep.c
  3.  *    
  4.  *    Extension for MacHack '93 contest (Flashin' when Beepin').
  5.  *    (based on example extension provided with PatchWorks)
  6.  *    
  7.  *    Written with PatchWorks by Robert (Mouse) Herrell and Patrick Beard.
  8.  *
  9.  *  Copyright (c) 1993 Charlie Reading.  All rights reserved.
  10.  */
  11.  
  12. #include <Menus.h>
  13. #include <Sound.h>
  14. #include <string.h>
  15. #include <Notification.h>
  16. #include <Traps.h>
  17. #include <stdarg.h>
  18. #include <stdio.h>
  19. #include <stddef.h>
  20.  
  21. #include <PWExceptions.h>
  22. #include <Extension.h>
  23. #include <GenericPatch.h>
  24.  
  25. static int dprintf(const char* format, ...);
  26.  
  27. //
  28. //    SysBeepPatch
  29. //
  30.  
  31. class SysBeepPatch : public GenericPatch {
  32. public:
  33.     SysBeepPatch();
  34.     virtual void Behavior(void);
  35. };
  36.  
  37. SysBeepPatch::SysBeepPatch()
  38. {
  39.     // install the appropriate patch.
  40.     GenericPatch::InitGenericPatch(_SysBeep, 0);
  41.     Install();
  42. }
  43.  
  44. void SysBeepPatch::Behavior()
  45.     {
  46.     short volume;
  47.     unsigned long firstTicks;
  48.     
  49.     // if sound level not 0 (because system will flash it then), flash the menu bar,
  50.     // delaying (8 ticks) so the user can catch their breath.
  51.     GetSoundVol(&volume);
  52.     if (volume != 0)
  53.         {
  54.         // Get the tick count so we can be sure when we start
  55.         firstTicks = TickCount();
  56.         
  57.         // Invert the bar
  58.         FlashMenuBar(0);
  59.         
  60.         // Wait until 8 ticks have elapsed (what happens when the sound is off)
  61.         while (TickCount() - firstTicks < 8)
  62.             ;
  63.         
  64.         // Invert the bar to restore it
  65.         FlashMenuBar(0);
  66.         }
  67.     }
  68.  
  69. //
  70. //    Install routine. This is where you allocate your patch objects.
  71. //    Throw an exception if something fails.
  72. //
  73.  
  74. void Install()
  75. {
  76.     short i;
  77.     long bogus;
  78.     
  79.     try
  80.         {
  81.         // if extension succeeds, show happy icon.
  82.         new SysBeepPatch;
  83.         ShowIconFamily(134);
  84.         }
  85.     catch
  86.         {
  87.         // extension failed, show sad icon.
  88.         ShowIconFamily(128);
  89.         throw(theException);
  90.         }
  91. }
  92.  
  93. //
  94. //    Remove routine. This is called when system is shutdown.
  95. //    Perhaps this should be removed. Rob thinks it shouldn't even be
  96. //    part of the design.
  97. //
  98.  
  99. void Remove()
  100. {
  101.     Patch::RemoveAll();
  102. }
  103.  
  104. //
  105. // debugging printf.
  106. //
  107.  
  108. static int dprintf(const char* format, ...)
  109. {
  110.     va_list args;
  111.     static char str[256];
  112.     int count;
  113.     
  114.     va_start(args, format);
  115.     count = vsprintf(str, format, args);
  116.     va_end(args);
  117.     DebugStr(c2pstr(str));
  118.         
  119.     return count;
  120. }
  121.